using System;
using SF.Code.Extension.ComputerLanguages;
using SG.Lang.Dry.Base;
using SG.Lang.Dry.Mirrors;

namespace SG.Lang.Dry.Code
{
    public class TypeRef : Element
    {
        private readonly TypeRefRecord _typeRefRecord;

        private TypeRef(ref ElementRecord elementRecord, ref TypeRefRecord typeRefRecord) : base(ref elementRecord)
        {
            _typeRefRecord = typeRefRecord;
        }

        public TypeCode TypeCode { get { return _typeRefRecord.TypeCode; } }

        public static TypeRef Create(ref ElementRecord elementRecord, ref TypeRefRecord typeRefRecord)
        {
            return new TypeRef(ref elementRecord, ref typeRefRecord);
        }

        public static TypeRef Create(Type type, DateTime time)
        {
            var guid = type.GUID;
            var elementRecord = new ElementRecord(ref guid, ElementKind.Type, time);
            var typeRefRecord = new TypeRefRecord(Type.GetTypeCode(type));
            return new TypeRef(ref elementRecord, ref typeRefRecord);
        }
    }
}